package com.always.electrical.energy.web.service;

import com.always.electrical.energy.mqtt.MqttClients;
import com.always.electrical.energy.web.data.entity.EfbsMaintMeasurement;
import com.always.electrical.energy.web.data.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class BaseService {

    @Autowired
    protected MqttClients mqttClients;

    // 功率曲线表
    @Autowired
    protected ICjGlqxService cjGlqxService;

    // 电压电流曲线表
    @Autowired
    protected ICjDydlqxService cjDydlqxService;

    @Autowired
    protected IIotMcuReposrtDataService iotMcuReposrtDataService;

    @Autowired
    protected IIotPcsReportDataService iotPcsReportDataService;

    @Autowired
    protected IIotSocReportDataService iotSocReportDataService;

    @Autowired
    protected IEfbsCapacitorCurveService efbsCapacitorCurveService;

    @Autowired
    protected ISvgCurveService svgCurveService;

    // 设备表
    @Autowired
    protected IEfbsMaintMeasurementService efbsMaintMeasurementService;

    @Autowired
    protected ICjMpptGlqxService cjMpptGlqxService;

    protected Map<BigDecimal, BigDecimal> getDeviceIdTmlIdMap(List<BigDecimal> ids) {
        return efbsMaintMeasurementService.lambdaQuery()
                .in(!ids.isEmpty(), EfbsMaintMeasurement::getId, ids)
                .list()
                .stream().collect(Collectors.toMap(EfbsMaintMeasurement::getId, EfbsMaintMeasurement::getTmlId));
    }

    protected Map<BigDecimal, String> getDeviceIdNodeIdMap(List<BigDecimal> ids) {
        return efbsMaintMeasurementService.lambdaQuery()
                .in(!ids.isEmpty(), EfbsMaintMeasurement::getId, ids)
                .list()
                .stream().collect(Collectors.toMap(EfbsMaintMeasurement::getId, EfbsMaintMeasurement::getNodeid));
    }
}
